package com.ease.util.keyboard {

   /**
    * Utility class to associate handler functions with keyboard
    * buttons plus modifiers
    */
   internal class KeyboardShortcutInfo {
      /** The uint keycode (as in flash.ui.Keyboard values) for the key to be bound
       *  to <code>handler</code>.
       */
      public var keyCode:uint;

      public var modifiers:int = 0;

      public var shortcutID:uint;

      private static var _nextShortcutID:uint = 0;

      /**
       * The method to be invoked when the specified key + modifier keys are pressed.
       * The signature is:
       *        <code>function keyHandler(keyCode:uint):void</code>
       */
      public var handler:Function;

      function KeyboardShortcutInfo(keyCode:uint, handler:Function,
                                    keyModifiers:uint) {
         this.keyCode = keyCode;
         this.handler = handler;

         modifiers = keyModifiers;
         shortcutID = _nextShortcutID++;
      }

      /**
       * This method verifies whether a particular shortcut matches the
       * specified keyboard key and modifiers.
       */
      public function isRequestedShortcut(requestedKeyCode:uint, ctrlKey:Boolean,
                                          shiftKey:Boolean, altKey:Boolean):Boolean {
         if (keyCode != requestedKeyCode) {
            return false;
         }

         if (useCtrlKey != ctrlKey) {
            return false;
         }

         if (useShiftKey != shiftKey) {
            return false;
         }

         if (useAltKey != altKey) {
            return false;
         }

         return true;
      }

      /**
       * Getter indicating whether the Ctrl key is associated with this shortcut
       */
      public function get useCtrlKey():Boolean {
         return (0 != (modifiers & KeyboardShortcutManager.CTRL_KEY));
      }

      /**
       * Getter indicating whether the Shift key is associated with this shortcut
       */
      public function get useShiftKey():Boolean {
         return (0 != (modifiers & KeyboardShortcutManager.SHIFT_KEY));
      }

      /**
       * Getter indicating whether the Alt key is associated with this shortcut
       */
      public function get useAltKey():Boolean {
         return (0 != (modifiers & KeyboardShortcutManager.ALT_KEY));
      }
   }
}
